package com.efuture.collection;
import java.util.*;

/**
 * @ClassNAME ListApiTest
 * @Description List集合特有api
 * @Author zhaoshanshan
 * @Date 2021/9/5 8:02 下午
 * @Version 1.0
 */
public class ListApiTest {

    public static void main(String[] args) {

        //addInxexElement();
        //getIndexElement();
        //getElementFirstIndex();
        //getElementLastIndex();
        //removeIndexElement();
        //alterIndexElement();
        listQuCong();
    }

    /**
     * 向List集合指定位置添加元素
     */
    private static void addInxexElement(){
        List arrayList = new ArrayList<>();
        arrayList.add("1");
        arrayList.add(2);
        arrayList.add(new Object());
        arrayList.add(1,"zss");

    }
    /**
     *根据下标获取List集合的元素
     */
    private static void getIndexElement(){
        List arrayList = new ArrayList<>();
        arrayList.add("1");
        arrayList.add(2);
        arrayList.add(new Object());
        arrayList.get(1);
    }
    /**
     *获取指定元素在集合里第一次出现的索引位置
     */
    private static void getElementFirstIndex(){
        List arrayList = new ArrayList<>();
        arrayList.add("1");
        arrayList.add(2);
        arrayList.add(new Object());
        int index = arrayList.indexOf("1");
        System.out.println(index);
    }
    /**
     *获取指定元素在集合里最后一次出现的索引位置
     */
    private static void getElementLastIndex(){
        List arrayList = new ArrayList<>();
        arrayList.add("1");
        arrayList.add(2);
        arrayList.add(new Object());
        int index = arrayList.lastIndexOf(2);
        System.out.println(index);
    }
    /**
     *List集合删除指定下标的元素
     */
    private static void removeIndexElement(){
        List arrayList = new ArrayList<>();
        arrayList.add("1");
        arrayList.add(2);
        arrayList.add(new Object());
        arrayList.remove(2);
    }
    /**
     *List集合修改指定位置的元素
     */
    private static void alterIndexElement(){
        List arrayList = new ArrayList<>();
        arrayList.add("1");
        arrayList.add(2);
        arrayList.add(new Object());
        arrayList.set(1,true);
    }

    /**
     * List去重
     */
    private static void listQuCong(){
        List list = new ArrayList();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("1");
        list.add("4");
        Set set = new HashSet(list);
        Iterator it = set.iterator();
        while (it.hasNext()){
            Object obj = it.next();
            System.out.println(obj);
        }


    }
}